<?php
/**
 * 搜窝
 *
 * @copyright 搜窝( www.souvo.com )
 * @package 前台用户登录
 * @version 1.0
 * @author wybwsk(wybwsk@qq.net)
 * @date 2011/5/2
 */
class MainAction extends FrontAction{
    protected function init() {
        $this->assign('user',$this->user);
        $this->assign('user_info',$this->user_info);
        $nav = F('nav_cate','',$this->cate_cache_path);
        if (!$nav){
            $nav = M('cate')->where('index_display = 1')->order('`order` ASC')->findAll();
            F('nav_cate',$nav,$this->cate_cache_path);
        }
        $this->assign('nav',$nav);
    }
    public function index() {
        //$ad = F('slider','',)
        $slider = F('slider','',DATA_PATH.'ad/');
        $about = F('about','',DATA_PATH);
        $this->assign('about',$about);
        $this->assign('slider',$slider);
         //实时资讯
        $data[12] = $this->getCateArticle(12);

        $data[11] = $this->getCateArticle(11);
        $data[16] = $this->getCateArticle(16,2);

        $this->assign('data',$data);
        $this->display();
    }
    private function getCateArticle($cid,$limit=5){
        if(abs($cid) === 0) return false;
        $cate = M('cate')->find($cid);
        if ($cate['single_page'] ==1){
            return M('article')->where(array('cid'=>$cid,'is_display'=>1))->order('update_time DESC')->find();
        }else{
            $limit = (empty($limit)) ? $limit = 5 : $limit;
            return M('article')->where(array('cid'=>$cid,'is_display'=>1))->order('update_time DESC')->limit("0,$limit")->findAll();
        }

    }

    public function articleList(){
        $cid = abs($_GET['cid']);
        $cate_db = D('Cate');
        $sub_cate_list = $cate_db->getCateList($cid);
        $cate_list = array_shift($sub_cate_list);
        $article_data = M('article')->where(array('cid'=>$cid,'is_display'=>1))->order('update_time DESC')->findAll();
        $this->assign('cate_list',$cate_list);
        $this->assign('sub_cate_list',$sub_cate_list);
        $this->assign('article_data',$article_data);
        $this->display();
    }

    public function show(){
        $aid = abs($_GET['aid']);
        if($aid === 0){
            alert('文章不存在','',2);
            exit;
        }
        $data = M('article')->find($aid);
        import("ORG.Net.Ubb");
        $ubb = new ubb($data['content']);
        $data['content'] = $ubb->showUbb();
        $ubb = new ubb($data['abstract']);
        $data['abstract'] = $ubb->showUbb();
        $this->assign('data',$data);
        $this->display();
    }
    public function people() {
        $data = M('member_info')->where(array('recommend'=>2))->order('`rorder` DESC')->findAll();
        $first_data = array_shift($data);
        $this->assign('procity',W('proCity',array(),true));
        $this->assign('data',$data);
        $this->assign('first_data',$first_data);
        $this->display();
    }
    public function blog() {
    }
}
